package com.atguigu.lease.common.config;

import com.atguigu.lease.common.minio.MinioProperties;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@EnableConfigurationProperties(MinioProperties.class)//启用对@ConfigurationProperties注解的支持相当于将MinioProperties类中的属性注入到spring容器中
@Configuration
public class MinioConfiguration {
    @Autowired
    private MinioProperties minioProperties;
    @Bean
    public MinioClient minioClient() {
        MinioClient.Builder builder = MinioClient.builder();//创建MinioClient对象
        MinioClient.Builder endpoint = builder.endpoint(minioProperties.getEndPoint());//设置连接地址
        MinioClient.Builder credentials =
                endpoint.credentials(minioProperties.getUsername(), minioProperties.getPassword());//设置用户名和密码

        return  credentials.build();//创建MinioClient对象并返回
    }

}
